package com.product.controller;

import com.product.result.ApiResult;
import com.product.service.IDefectLogService;
import com.product.utils.PageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "缺陷日志控制器")
@RestController
@RequestMapping("/defectlog")
public class DefectLogController {
    @Autowired
    private IDefectLogService deleteDefectLog;

    @Parameters({
            @Parameter(name = "size", description = "每页条数，默认10条"),
            @Parameter(name = "current", description = "分页页数，默认第一页"),
            @Parameter(name = "lineId", description = "流水线id"),
            @Parameter(name = "orderItemId", description = "订单项id"),
            @Parameter(name = "timeOrderBy", description = "按照创建时间顺序排序,0->升序,1->降序"),
            @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    })
    @Operation(summary = "获取所有缺陷日志")
    @GetMapping("/all")
    private ApiResult<PageUtils> getAllDefectLogs(@RequestParam(name = "size", defaultValue = "10") Integer size,
                                             @RequestParam(name = "current", defaultValue = "1") Integer current,
                                             @RequestParam(name = "lineId", required = false) Integer lineId,
                                             @RequestParam(name = "orderItemId", required = false) Integer orderItemId,
                                             @RequestParam(name = "timeOrderBy", defaultValue = "1") Integer timeOrderBy) {
        return ApiResult.ok(deleteDefectLog.getAllDefectLog(size, current, lineId, orderItemId,timeOrderBy));
    }


    @Parameters({
            @Parameter(name = "DefectLogId", description = "缺陷日志id"),
            @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    })
    @Operation(summary = "删除缺陷日志")
    @PostMapping("/delete")
    private ApiResult<Boolean> deleteDefectLog(@RequestParam(name = "DefectLogId") Integer DefectLogId) {
        deleteDefectLog.deleteDefectLog(DefectLogId);
        return ApiResult.ok();
    }

    @Parameter(name = "token", description = "用户token,放到请求头的Authorization属性")
    @Operation(summary = "批量删除缺陷日志")
    @PostMapping("/deletes")
    private ApiResult<Boolean> deleteDefectLogs(@RequestBody List<Integer> DefectLogIds) {
        deleteDefectLog.deleteDefectLogs(DefectLogIds);
        return ApiResult.ok();
    }
}
